﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        // 确认注册
        protected void btn_Regin_Click(object sender, EventArgs e)
        {
            var user = txt_User.Text.Trim();
            var pwd = txt_Pwd.Text.Trim();
            var rePwd = txt_Repwd.Text.Trim();
            if (user == "")
            {
                Response.Write("<script>alert('账号不能为空！')</script>");
            }
            else if (pwd == "")
            {
                Response.Write("<script>alert('密码不能为空！')</script>");
            }
            else if (rePwd == "")
            {
                Response.Write("<script>alert('确认密码不能为空！')</script>");
            }
            else
            {
                var sql = string.Format("select * from AdminInfo where UserName = '{0}'", user);
                var dt = DbHelp.getSelect(sql);
                if (dt.Rows.Count == 1)
                {
                    Response.Write("<script>alert('账号已存在！')</script>");
                }
                else
                {
                    if (pwd != rePwd)
                    {
                        Response.Write("<script>alert('两次密码不一致！')</script>");
                    }
                    else
                    {
                        var sqlAdd = string.Format("insert into AdminInfo(UserName, PassWord) values('{0}', '{1}')", user, pwd);
                        DbHelp.getIDU(sqlAdd);
                        Response.Write("<script>alert('注册成功！')</script>");
                    }
                }
            }
        }
        // 退出
        protected void btn_Canner_Click(object sender, EventArgs e)
        {
            Response.Redirect("Login.aspx");
        }
    }
}